<template>
  <div id="container" style="height:100vh;width:100vw;">

  </div>
</template>

<script>
import * as Three from 'three'
// 导入轨道控制器
import {
  OrbitControls
} from 'three/examples/jsm/controls/OrbitControls'
// import {RGBELoader} from 'three/examples/jsm/loaders/RGBELoader'
let scene = null,
  camera = null,
  renderer = null,
  mesh = null
export default {
  data () {
    return {

    };
  },
  methods: {
    init () {
      let container = document.getElementById('container');

      // 添加相机
      camera = new Three.PerspectiveCamera(70, container.clientWidth / container.clientHeight, 0.01, 1000);
      // 相机的位置
      camera.position.z = 0.1

      // 场景
      scene = new Three.Scene()
      // 创建球
      let geometry = new Three.SphereBufferGeometry(5, 32, 32)
      let a = new Three.TextureLoader().load(`static/all.jpg`)

      let material = new Three.MeshBasicMaterial({ map: a });
      mesh = new Three.Mesh(geometry, material);
      mesh.geometry.scale(1, 1, -1);
      scene.add(mesh);

      // 初始化渲染器
      renderer = new Three.WebGLRenderer({ antialias: true });
      // 渲染器的大小
      renderer.setSize(container.clientWidth, container.clientHeight);
      // 将渲染器添加到页面
      container.appendChild(renderer.domElement);



      // 创建轨道控制器 相机围绕模型看到的角度
      const OrbitControl = new OrbitControls(camera, renderer.domElement)
      // 设置轨道自然
      OrbitControl.enableDamping = true
      // 设置惯性
      OrbitControl.update()


    },
    animate () {
      // 浏览器自动渲染下一帧
      requestAnimationFrame(this.animate);

      // 渲染到页面
      renderer.render(scene, camera);
    }
  },
  mounted () {
    this.init()
    this.animate()
  }

}

</script>
<style scoped>
#container {
  width: 100vw;
  height: 100vh;
}
</style>